<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<body>

<script type="text/javascript">
$(function() {
	//alert('ok');
	djt_FSsob_editIndex = undefined;
	
	$('#djt_FSsob_dg').datagrid({
    	url:'../floatSalary/querySobByPage',
    	columns:[[
    		{field:'',title:'',checkbox:true},
			{field:'floatSalarySobId',title:'编号',width:'60',sortable:true},
			{field:'floatSalarySobName',title:'浮动薪资账套名',width:'115',
				formatter: function(value,row,index){
					return '<a href="#" onclick="addTab(&#39;浮动薪资表：'+row.floatSalarySobName+'&#39;, &#39;../salary/float_salary?Sobid='+row.floatSalarySobId+'&#39;)">'+row.floatSalarySobName+'</a>'
				},
				editor:{type:'text',options:{required:true}}},
			{field:'builder',title:'创建者',width:'100'},
			{field:'buildDate',title:'创建日期',width:'120',sortable:true},
			{field:'remark',title:'备注',width:'170',editor:{type:'text'}}
		]],
		fit:true,
 	   	fitColumns:false,
 	   	//隔行变色
 	   	striped:true,
  	  	nowrap:true,
		toolbar:'#FSsobtb',
		pagination:true,
		pageSize:5,
		pageList:[5,10,20,40],
		border:false,
		sortName:'floatSalarySobId',
		sortOrder:'asc',
		onAfterEdit : function(rowIndex,rowData,changes){
			var inserted = $('#djt_FSsob_dg').datagrid('getChanges','inserted');
			var updated = $('#djt_FSsob_dg').datagrid('getChanges','updated');
			var url = '';
			if(inserted.length > 0){
				url = '../floatSalary/insertSob';
			}
			if(updated.length > 0){
				url = '../floatSalary/updateSob';
			}
			var djt_FSsob_rowData = JSON.stringify(rowData);
			$.post(url,{djt_FSsob_rowData},function(e){
				var info = JSON.parse(e);
				//console.log(info);
				if(info.success){
					$('#djt_FSsob_dg').datagrid('acceptChanges');
					$.messager.show({
						title:'成功',
						msg:info.msg,
					});
				}else{
					$('#djt_FSsob_dg').datagrid('rejectChanges');
					$.messager.alert('错误',info.msg,'error');
				}
			})
			djt_FSsob_editIndex = undefined;
			$('#djt_FSsob_dg').datagrid('unselectAll');
		},
		onDblClickRow : function(rowIndex,rowData){
			if(djt_FSsob_editIndex != undefined){
				$('#djt_FSsob_dg').datagrid('endEdit',djt_FSsob_editIndex);
				djt_FSsob_editIndex = undefined;
			}
			if(djt_FSsob_editIndex == undefined){
				$('#djt_FSsob_dg').datagrid('beginEdit',rowIndex);
				djt_FSsob_editIndex = rowIndex;
			}
		}
	});
});

//模糊查询
function searchFSsobName(value){
	 $('#djt_FSsob_dg').datagrid('load','../floatSalary/findSobByPage?floatSalarySobName='+value);
}

//增加
function addFSsob(){
	if(djt_FSsob_editIndex != undefined){
		$('#djt_FSsob_dg').datagrid('endEdit',djt_FSsob_editIndex);
	}
	if(djt_FSsob_editIndex == undefined){
		$('#djt_FSsob_dg').datagrid('insertRow',{
			index : 0,
			row:{
				
			}
		});
		$('#djt_FSsob_dg').datagrid('beginEdit',0);
		djt_FSsob_editIndex = 0;
	}
}

//保存
function saveFSsob(){
	$('#djt_FSsob_dg').datagrid('endEdit',djt_FSsob_editIndex);
}

//删除
function removeFSsob(){
	var rows = $('#djt_FSsob_dg').datagrid('getSelections');
	if(rows.length > 0){
		$.messager.confirm('请确认','您确定要删除当前所有选中的项目吗？',function(r){
			if(r){
				var ids = [];
				for(var i = 0; i < rows.length; i++){
					ids.push(rows[i].floatSalarySobId)
				}
				var djt_FSsob_rowData = JSON.stringify(ids);
				$.post('../floatSalary/deleteSob',{djt_FSsob_rowData},function(e){
					var info = JSON.parse(e);
					if(info.success){
						$('#djt_FSsob_dg').datagrid('load');
						$('#djt_FSsob_dg').datagrid('unselectAll');
						$.messager.show({
							title:'成功',
							msg:info.msg,
						});
					}else{
						$('#djt_FSsob_dg').datagrid('rejectChanges');
						$.messager.alert('错误',info.msg,'error');
					}
				})
				djt_FSsob_editIndex = undefined;
			}
		})
	}else{
		$.messager.alert('提示','请选择要删除的记录！','error');
	}
}

//编辑
function editFSsob(){
	var rows = $('#djt_FSsob_dg').datagrid('getSelections');
	if(rows.length == 1){
		if(djt_FSsob_editIndex != undefined){
			$('#djt_FSsob_dg').datagrid('endEdit',djt_FSsob_editIndex);
		}
		if(djt_FSsob_editIndex == undefined){
			var index = $('#djt_FSsob_dg').datagrid('getRowIndex',rows[0]);
			$('#djt_FSsob_dg').datagrid('beginEdit',index);
			djt_FSsob_editIndex = index;
			$('#djt_FSsob_dg').datagrid('unselectAll');
		}
	}else{
		$.messager.show({
			title:'提示',
			msg:'一次只能编辑一行！',
		});
	}
}

//撤销编辑
function rejectFSsob(){
	djt_FSsob_editIndex = undefined;
	$('#djt_FSsob_dg').datagrid('rejectChanges');
	$('#djt_FSsob_dg').datagrid('unselectAll');
}
</script>

<div class="easyui-layout" fit="true" border="false">
	<div region="center" border="false">
		<table id="djt_FSsob_dg"></table>
	
		<div id="FSsobtb">
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="addFSsob()">添加</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="removeFSsob()">删除</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true" onclick="editFSsob()">编辑</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="saveFSsob()">保存</a>
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="rejectFSsob()">撤销编辑</a>
			<img alt="搜索框" src="../djt/img/搜索.png">
			浮动工资账套名：
			<!--搜索框-->
			<input class="easyui-searchbox" style="width:200px" data-options="searcher:searchFSsobName"></input>
		</div>
	</div>	
</div>
</body>